#ifndef _BOARD_H_
#define _BOARD_H_

#include "app_config.h"
#include "n32g45x.h"
#include "mcu.h"

#define BSP_MCU_MODEL       POLSYS_MCU_N32

#define SRAM_SIZE      144      // KB
#define SRAM_END       (SRAM_BASE + SRAM_SIZE * 1024)
#if defined(__CC_ARM) || defined(__CLANG_ARM)
extern int Image$$RW_IRAM1$$ZI$$Limit;
#define HEAP_BEGIN      ((void *)&Image$$RW_IRAM1$$ZI$$Limit)
#elif __ICCARM__
#pragma section="CSTACK"
#define HEAP_BEGIN      (__segment_end("CSTACK"))
#else
extern int __bss_end;
#define HEAP_BEGIN      ((void *)&__bss_end)
#endif
#define HEAP_END        ((void *)SRAM_END)



#if APP_DRIVE_SELECT == 1
#define RT_CONSOLE_DEVICE_NAME      "usart1"
int rt_hw_usart_init();
#define Board_InitConsoleDevice()   rt_hw_usart_init()

#define LED_PIN     GET_PIN(B, 5)
#define Led_On()		rt_pin_write(LED_PIN, PIN_HIGH)
#define Led_Off()		rt_pin_write(LED_PIN, PIN_LOW)
#define Led_Init()		rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);
#define Led_IsOn()      rt_pin_read(LED_PIN)

#else
void Board_InitConsoleDevice();   
#define Led_Init()
STATIC_FORCE_IN_LINE void Led_On()      {GPIOB->PBSC = GPIO_PIN_5;}
STATIC_FORCE_IN_LINE void Led_Off()     {GPIOB->PBC = GPIO_PIN_5;}
STATIC_FORCE_IN_LINE bool Led_IsOn()    {return GPIO_ReadOutputDataBit(GPIOB, GPIO_PIN_5);}
#endif



#define Board_GetTickCycleValue()   SYSTICK_VALUE
#define Board_GetTickNowValue()     (u32)(SYSTICK_VALUE - SysTick->VAL)


#endif
